package main

import (
	"flag"
	"fmt"

	"longbri/rpc/internal/config"
	//"longbri/rpc/internal/crontab"
	"longbri/rpc/internal/server"
	"longbri/rpc/internal/svc"
	"longbri/rpc/pb/dashboard"

	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/core/service"
	"github.com/zeromicro/go-zero/zrpc"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
)

var configFile = flag.String("f", "etc/dashboard.yaml", "the config file")

func main() {
	flag.Parse()

	var c config.Config
	conf.MustLoad(*configFile, &c)
	ctx := svc.NewServiceContext(c)

	s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
		dashboard.RegisterDashboardServer(grpcServer, server.NewDashboardServer(ctx))

		if c.Mode == service.DevMode || c.Mode == service.TestMode {
			reflection.Register(grpcServer)
		}
	})
	defer s.Stop()

	//longport
	/*
		lc, err := lconfig.New()
		if err != nil {
			log.Fatal(err)
			return
		}

		// init http client from config
		quoteContext, err := quote.NewFromCfg(lc)
		if err != nil {
			log.Fatal(err)
			return
		}
		defer quoteContext.Close()

		lctx := context.Background()

		quotes, err := quoteContext.Quote(lctx, []string{"700.HK", "AAPL.US", "TSLA.US", "NFLX.US"})
		if err != nil {
			log.Fatal(err)
			return
		}
		fmt.Printf("quotes: %v", quotes)
	*/

	//定时任务
	// scheduler, err := crontab.InitScheduler(ctx)
	// if err != nil {
	// 	fmt.Printf("Failed to initialize scheduler: %v", err)
	// }
	// scheduler.Start()

	fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
	s.Start()
}
